package cn.fancylab.template.web.action.admin;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import cn.fancylab.model.acl.AuthUser;
import cn.fancylab.monitor.MonitorService;
import cn.fancylab.template.web.action.AnnotationController;
/**
 * @author <a href="mailto:acerge@163.com">gebiao(acerge)</a>
 */
public abstract class BaseAdminController extends AnnotationController {
	
	@Autowired @Qualifier("jdbcTemplate")
	protected JdbcTemplate jdbcTemplate;
	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	@Autowired@Qualifier("monitorService")
	protected MonitorService monitorService;
	public void setMonitorService(MonitorService monitorService) {
		this.monitorService = monitorService;
	}
	protected final AuthUser getLogonUser(){
		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
		if(auth == null) return null;
		if(auth.isAuthenticated() && !auth.getName().equals("anonymous")){//登录
			AuthUser user = (AuthUser) auth.getPrincipal();
			if(StringUtils.equals("user", user.getUsertype())){
				return user;
			}
		}
		return null;
	}

}
